@extends('layouts.app')
@section('content')
    <div class="layui-form" lay-filter="layuiadmin-form-categories" id="layuiadmin-app-form-categories">
        <div class="layui-form-item">
            <label class="layui-form-label">上级分类</label>
            <div class="layui-input-inline">
                <select name="parent_id" lay-search  lay-filter="parent_id">
                    <option value="0">一级分类</option>
                    @foreach($categories as $first)
                        <option value="{{ $first['id'] }}" @if(isset($category->parent_id)&&$category->parent_id==$first['id']) selected @endif>{{ $first['name'] }}</option>
                        @if(isset($first['sub']))
                            @foreach($first['sub'] as $second)
                                <option value="{{$second['id']}}" {{ isset($category->id) && $category->parent_id==$second['id'] ? 'selected' : '' }} >┗━━{{$second['name']}}</option>
                            @endforeach
                        @endif
                    @endforeach
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" value="{{ $category->name ?? old('name') }}" lay-verify="required" placeholder="请输入..." autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类图标</label>
            <div class="layui-input-inline">
                <input type="text" name="icon" value="{{ $category->icon ?? '' }}"
                    placeholder="请选择图片" autocomplete="off" class="layui-input">
            </div>
            <button style="float: left;" type="button" class="layui-btn" layadmin-event="select_image">选择图片</button>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <script type="text/html" template>
                    <input type="number" name="sort" value="{{ $category->sort ?? 0 }}" lay-verify="required" placeholder="请输入..." autocomplete="off" class="layui-input">
                </script>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <select name="status" lay-verify="required">
                    <option value="1" @if (isset($category->sort)&&$category->sort === 1) 'selected' : '' @endif>启用</option>
                    <option value="0" @if (isset($category->sort)&&$category->sort === 0) 'selected' : '' @endif>禁用</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-app-content-category-submit" id="LAY-user-front-submit" value="确认">
        </div>
    </div>
@endsection
@section('js')
    <script>
        layui.use(['index', 'form'], function(){
            var $ = layui.$
                ,form = layui.form ;
        })
    </script>
@endsection
